﻿using System.Drawing;
using System.Collections;

namespace TestAnimation
{
    class Ship:ScreenObject
    {
        public int energy;
        public Ship()
        {
            position = new Vector((float)Globals.maxX/2, (float)Globals.maxY/2);
            CourseOrientation = 0;
            ObjectOrientation = 0;
            Speed = 0;
            SetVelocity();
            points = new ArrayList(3);
            transformedPoints=new ArrayList(3);
            energy = 100;

            objectWidth = 200;
            objectHeight = 600;
            objectSize = objectHeight;

            points.Add(new Point(-objectHeight / 2, objectWidth / 2));
            points.Add(new Point(0, objectWidth / 4));
            points.Add(new Point(objectHeight / 2, 0));
            points.Add(new Point(0, -objectWidth/4));
            points.Add(new Point(-objectHeight / 2, -objectWidth / 2));
        }

        public override void Move()
        {
            speed /= Globals.friction;
            SetVelocity();
            base.Move();
        }

        public Particle NewParticle()
        {
            var exitPoint = new Vector(- objectHeight / 2f, Helper.GetRnd(objectWidth) - objectWidth / 2);
            exitPoint = exitPoint.Rotate((float)objectOrientation) + position;
            var vel = new Vector(0 - 40f, 0).Rotate((float)objectOrientation) + velocity * .5f;

            return (new Particle(exitPoint, vel, 0));
        }

        public Vector BulletExitPoint
        {
            get
            {
                var exitPoint = new Vector(objectWidth,0);
                return( exitPoint.Rotate((float)objectOrientation) + position);            
            }
        }

        public void Thrust()
        {
            var impulse = new Vector(1, 0);
            velocity += impulse.Rotate((float)objectOrientation);
            courseOrientation = velocity.Angle();
            Speed = velocity.Magnitude();
        }
    }
}
